{% import "components/user.html" as user with context %}
{% macro reply(mode_create, udoc, doc = {}, rdoc = {}) %}
<li class="dczcomments__reply{% if mode_create %} commentbox-container{% endif %}">
  <div class="media">
    <div class="media__left top">
      <img src="{{ udoc['gravatar']|gravatar_url }}" width="50" height="50" class="medium user-profile-avatar">
    </div>
    <div class="media__body top no-heading">
    {% if not mode_create %}
      <div class="clearfix">
        <div class="supplementary dczcomments__supplementary">
          {{ user.render_inline(udoc, dudict[udoc['_id']], avatar=false) }}
          @ {{ datetime_span(rdoc['_id'].generation_time) }}
        </div>
        {{ comment_base.reply_operations(doc, rdoc) }}
      </div>
      <div class="typo" data-emoji-enabled data-raw-url="{{ reverse_url('discussion_tail_reply_raw', did=doc['parent_doc_id'], drid=doc['doc_id'], drrid=rdoc['_id']) }}">
        {{ rdoc['content']|markdown }}
      </div>
      <div class="commentbox-edit-target"></div>
    {% else %}
      <div class="commentbox-placeholder"></div>
    {% endif %}
    </div>
  </div>
</li>
{% endmacro %}

{% macro comment(mode_create, udoc, doc = {}) %}
<li class="dczcomments__item">
  <div class="media">
    <div class="media__left top">
      <img src="{{ udoc['gravatar']|gravatar_url }}" width="60" height="60" class="medium user-profile-avatar">
    </div>
    <div class="media__body top no-heading">
    {% if not mode_create %}
      <div class="clearfix">
        <div class="supplementary dczcomments__supplementary">
          {{ user.render_inline(udoc, dudict[udoc['_id']], avatar=false) }}
          @ {{ datetime_span(doc['_id'].generation_time) }}
        </div>
        {{ comment_base.comment_operations(doc) }}
      </div>
      <div class="typo" data-emoji-enabled data-raw-url="{{ reverse_url('discussion_reply_raw', did=doc['parent_doc_id'], drid=doc['doc_id']) }}">
        {{ doc['content']|markdown }}
      </div>
      <div class="commentbox-edit-target"></div>
      <ul class="dczcomments__replies commentbox-reply-target">
      {% for rdoc in doc['reply'] %}
        {{ reply(mode_create, udict[rdoc['owner_uid']], doc, rdoc) }}
      {% endfor %}
      </ul>
    {% else %}
      {{ comment_base.comment_form() }}
      <div class="commentbox-placeholder"></div>
      <ul style="display:none">
        {{ reply(mode_create, udoc) }}
      </ul>
    {% endif %}
    </div>
  </div>
</li>
{% endmacro %}
